using B.S.DataBase.Infrastructure;
using Microsoft.EntityFrameworkCore;
using System.Reflection;

namespace B.S.DataBase.Read.API
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddControllers();
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();

            builder.Services.AddSwaggerGen(x => {
                var path = AppDomain.CurrentDomain.BaseDirectory + "B.S.DataBase.Read.API.xml";
                x.IncludeXmlComments(path, true);
            });


            builder.Services.AddDbContext<BussionDbContext>(x =>
            {
                x.UseSqlServer(builder.Configuration.GetConnectionString("db"));
            });

            builder.Services.AddMediatR(x =>
            {
                x.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
            });
            builder.Services.AddAutoMapper(typeof(MapperProfile));

            builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));



            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }
            app.UseCors(x =>
            {
                x.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
            });
            app.UseHttpsRedirection();

            app.UseAuthorization();


            app.MapControllers();

            app.Run();
        }
    }
}
